#include "StdAfx.h"
#include "GImageUtil.h"

#include <corona.h>

GImageUtil::GImageUtil()
{
}


GImageUtil::~GImageUtil()
{
}

GImage * GImageUtil::CreateImage( const char * fileName ){
	corona::Image* image = corona::OpenImage( fileName, corona::PF_R8G8B8A8 );
	if( !image )
		return 0;
	int width = image->getWidth();
	int height = image->getHeight();
	void* pixels = image->getPixels();
	GImage* gImage = new GImage( width, height );
	GImage::byte* p = static_cast< GImage::byte* >( pixels );
	for( int i = 0; i < width * height; ++i ){
		GImage::byte r = *p++;
		GImage::byte g = *p++;
		GImage::byte b = *p++;
		GImage::byte a = *p++;
		gImage->setPixel( i % width, i / width, GImage::color( r, g, b ) );
	}
	return gImage;
}
